package com.ly.hotel.spainterface.pp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ly.hotel.R;
import com.ly.hotel.common.MyApplication;
import com.ly.hotel.spainterface.pp.bean.PreXFDataBean;
import com.ly.hotel.util.ImageUtil;

import java.util.List;

/**
 * Created by mo on 2018/6/9.
 */

public class PpXFPopListAdapter extends BaseAdapter {

    private Context context;
    private List<PreXFDataBean> preXFDataBeans;
    private int rod = 0;

    public PpXFPopListAdapter(Context context, List<PreXFDataBean> preXFDataBeans) {
        this.context = context;
        this.preXFDataBeans = preXFDataBeans;
        rod = context.getResources().getDimensionPixelSize(R.dimen.px6);
    }

    @Override
    public int getCount() {
        return preXFDataBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return preXFDataBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        ViewHolder viewHolder = null;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.pp_pop_gridview_consume_item, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.consumeItemImage = view.findViewById(R.id.consume_item_image);
            viewHolder.consumeItemName = view.findViewById(R.id.consume_item_name);
            viewHolder.consumeItemPrice = view.findViewById(R.id.consume_item_price);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        PreXFDataBean preXFDataBean = preXFDataBeans.get(position);
        String imageUrl = MyApplication.getHostResUrl() + "/upload/" + preXFDataBean.getImg();
        ImageUtil.displayImage_Round(context, imageUrl, viewHolder.consumeItemImage, rod);
        viewHolder.consumeItemName.setText(preXFDataBean.getName());
        viewHolder.consumeItemPrice.setText(preXFDataBean.getPrice() + "元/" + preXFDataBean.getMeasure());
        return view;
    }

    class ViewHolder {
        ImageView consumeItemImage;
        TextView consumeItemName;
        TextView consumeItemPrice;
    }
}
